package com.lp.biz.coupon.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lp.biz.coupon.model.entity.BizCoupon;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import static com.lp.common.constant.CommonConstant.DATE_TIME;
import static com.lp.common.constant.CommonConstant.TIMEZONE;
import static com.lp.common.utils.Tools.stripTrailingZeros;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-07-22 21:45:01
 */
@Data
public class CouponList {

    private Integer id;

    private BigDecimal amount;

    private BigDecimal condition;

    private Integer gainType;

    private Integer useType;

    private Integer validityDays;

    @JsonFormat(timezone = TIMEZONE, pattern = DATE_TIME)
    private LocalDateTime createAt;

    public static CouponList builder(BizCoupon bizCoupon) {
        CouponList couponList = new CouponList();
        couponList.setId(bizCoupon.getId());
        couponList.setAmount(stripTrailingZeros(bizCoupon.getAmount()));
        couponList.setCondition(stripTrailingZeros(bizCoupon.getCondition()));
        couponList.setGainType(bizCoupon.getGainType());
        couponList.setUseType(bizCoupon.getUseType());
        couponList.setValidityDays(bizCoupon.getValidityDays());
        couponList.setCreateAt(bizCoupon.getCreateAt());
        return couponList;
    }
}
